﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Linq;

using DnaCoreLib;
using DnaDataLib;




namespace DnaServiceLib
{
    public class AccountManager
    {
        public AccountManager()
        {
        }

        public bool Login(string username)
        {

            using (DnaDataLib.DnaGedDataContext GenDc = new DnaDataLib.DnaGedDataContext())
            {
                var account = GenDc.Accounts
                    .Where(w => w.Username == username)
                    .FirstOrDefault();

                if (account == null)
                    return false;
                else
                    return true;
            }
        }

        public List<Account> AccountList
        {
            get
            {
                using (DnaDataLib.DnaGedDataContext DnaDc = new DnaDataLib.DnaGedDataContext())
                {
                    return DnaDc.Accounts.Select(s => new Account(s.Id, s.Username)).ToList();
                }
            }
        }

        public void AddNewAccount(Account account)
        {
            string username = account.Username;
            using (DnaDataLib.DnaGedDataContext DnaDc = new DnaDataLib.DnaGedDataContext())
            {
                DnaDataLib.Account newAccount = new DnaDataLib.Account() { Id = Guid.NewGuid(), Username=username, };
                DnaDc.Accounts.InsertOnSubmit(newAccount);
                DnaDc.SubmitChanges();


            }
        }

    }
}
